package mrh.niubi.librarysystem.service.impl;

import mrh.niubi.librarysystem.mapper.OrderMapper;
import mrh.niubi.librarysystem.pojo.Order;
import mrh.niubi.librarysystem.service.OrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;

@Service
public class OrderServiceImpl implements OrderService {

    @Resource
    private OrderMapper orderMapper;
    @Override
    public List<Order> getOrdersByUsername(String username) {
        return orderMapper.getOrdersByUsername(username);
    }

    @Override
    public int addOrder(Order order) {
        Date startDate = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(startDate);
        calendar.add(Calendar.DATE, 30);
        Date endDate = calendar.getTime();
        order.setStartTime(startDate);
        order.setEndTime(endDate);
        order.setState("待支付");
        System.out.println(order.getStartTime() +"\n" + order.getEndTime());
        return orderMapper.insert(order);
    }

    @Override
    public int updateOrder(Order order) {
        return orderMapper.updateById(order);
    }

    @Override
    public int delOrderById(String id) {
        return orderMapper.deleteById(id);
    }

    @Override
    public Order getOrderById(String id) {
        return orderMapper.selectById(id);
    }

    @Override
    public List<Order> selectOrdersByQueryinf(String inf,String username) {
        return orderMapper.selectOrdersByQueryinf(inf,username);
    }

}
